package com.beetlestech.nfe.main.biz.com.impl;

import com.beetlestech.nfe.fw.core.biz.AbstractDBLogic;
import com.beetlestech.nfe.main.biz.com.HbCloseOrder;
import com.beetlestech.nfe.main.biz.com.HbStudent;
import com.beetlestech.nfe.main.biz.constant.CommonConstant;
import com.beetlestech.nfe.main.biz.constant.CtgCodeConstant;
import com.beetlestech.nfe.main.biz.constant.HbMessageCode;
import com.beetlestech.nfe.main.db.base.StatementDTO;
import com.beetlestech.nfe.main.db.base.StatementUtil;
import com.beetlestech.nfe.main.db.constant.SQLConstant;
import com.beetlestech.nfe.main.db.constant.SQLID;
import com.beetlestech.nfe.main.db.tbl.MststudentDTO;
import com.beetlestech.nfe.main.db.tbl.OrderdetailDTO;
import com.beetlestech.nfe.main.db.tbl.StudentorderDTO;

public class HbCloseOrderImpl extends AbstractDBLogic implements HbCloseOrder, CtgCodeConstant, HbMessageCode, CommonConstant, SQLConstant {
	@Override
	public void closeOrder(
			String actionType,
			String orderSql,
			Integer orderId) {
		if(actionType.equals("single")){
			StudentorderDTO  studentorderDTO=new StudentorderDTO();
			studentorderDTO.setorderid(orderId);
			studentorderDTO.setstate(Integer.parseInt(CATAGORY_P_ORDER_STATE.CLOSED.toString()));
			updateDAO.updateOne(StudentorderDTO.UPDATE, studentorderDTO, M10190WS);
			OrderdetailDTO orderdetailDTO =new OrderdetailDTO();
			orderdetailDTO.setorderid(orderId);
			orderdetailDTO.setstate(Integer.parseInt(LEARNING_STATE.NOT_GENERATE.toString()));
			updateDAO.update(SQLID.ORDER_DETAIL_UPDATE_BY_ORDER_ID, orderdetailDTO);
			
		}else if(actionType.equals("many")){
			String[] dbSqlArray=orderSql.split(",");
			for (int i = 0; i < dbSqlArray.length; i++) {
				StudentorderDTO  studentorderDTO=new StudentorderDTO();
				studentorderDTO.setorderid(Integer.parseInt(dbSqlArray[i]));
				studentorderDTO.setstate(Integer.parseInt(CATAGORY_P_ORDER_STATE.CLOSED.toString()));
				updateDAO.updateOne(StudentorderDTO.UPDATE, studentorderDTO, M10190WS);
				OrderdetailDTO orderdetailDTO =new OrderdetailDTO();
				orderdetailDTO.setorderid(Integer.parseInt(dbSqlArray[i]));
				orderdetailDTO.setstate(Integer.parseInt(LEARNING_STATE.NOT_GENERATE.toString()));
				updateDAO.update(SQLID.ORDER_DETAIL_UPDATE_BY_ORDER_ID, orderdetailDTO);
			}
		}
	}


}
